<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once(SERVER_FS_ROOT."/app/util/imex/_inc/importExport.func.php");

$objUser = $_SESSION[USEROBJ];
$numElem = 0;
$errMsg = "";
//carico l'elenco delle librerie
$sSQL = "SELECT * FROM library ORDER BY library";
if(!$query = $objSDAO->query($sSQL, "sel")){
	$errMsg = $objSDAO->error;
	$errCode = $objSDAO->errno;
}
if(sxREQ("reqtype") == "libExp"){
	$errMsg .= libExp();		
}
//output HTML
$aOpz = array("kMenu"=>'pro.fun');
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>  
<script language="JavaScript" type="text/javascript">
function libExp() {
	document.objFrm.reqtype.value = 'libExp';
	document.objFrm.submit();
}
</script>
<?php
echo(bodyHTML($aOpz));


$aCmd = array(
					"newexp"=>array("pag"=>"javascript:libExp();",
										"title"=>_t("export"),
										"text"=>_t("export"),
										"perm"=>"newfun",'align'=>'L'),
					"ins"=>array("pag"=>"libraryIns.php",
										"title"=>_t("add new librar"),
										"text"=>_t("new library"),
										"perm"=>"newfun"),
					"back"=>array()
					);
echo(commandsHTML($aCmd));	

echo("<form name=\"objFrm\" id=\"objFrm\" action=\"libraryList.php\" method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");

//output dei dati
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"titl01\" colspan=\"4\">List of libraries</td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"1%\">Export</td>" .
		"<td class=\"tabh01\" width=\"9%\">Library</td>" .
		"<td class=\"tabh01\" width=\"89%\">Description</td>" .
		"<td class=\"tabh01\" width=\"1%\">&nbsp;</td>" .
	"</tr>\n");	
while($row = $objSDAO->fetch("sel")){
	echo("<tr>" .
			"<td class=\"text01\" valign='top'>" .
			"<input type=\"checkbox\" value=\"".$row["library"]."\" name=\"exp_".$row["library"]."\" class='text01'></td>" .
			"<td class=\"text01\" valign='top'><a class=\"text01\" ".
				goToPag("../func/functionList.php?lbr=".$row["library"]."&xsn=".XSN).
				" title=\"List of functions\">".
				$row["library"]."</a></td>\n" .
			"<td class=\"text01\" valign='top'>".sxHE($row["description"])."</td>" .
			"<td class=\"text01\" valign='top'><a class=\"text01\" ".
				goToPag("libraryMod.php?lbr=".$row["library"]."&xsn=".XSN).
				" title=\"change definition\">".
				"<img src='".SERVER_URL_ROOT."/app/_img/b_edit.png' border='0' /></a></td>\n" .
				"</tr>\n");
}
echo("</table>\n");
echo(commandsHTML($aCmd));
echo("</form>");
echo(footerHTML());
exit();

function libExp() {
	global $objUser;
	$aReqExp = array();
 	foreach($_REQUEST as $key=>$value) {
 		if(substr($key,0,4) == "exp_") {
  			$aReqExp[] = array('library',$value);
  			$objUser->setHistoryVar(array($key=>''));
 		}
 	}
  	$objUser->setHistoryVar(array('reqtype'=>''));
	if (count($aReqExp) == 0) {
		return "No item selected";
	}
	$errMsg = tabExport($aReqExp);
	return $errMsg;
}

?>